package SwingForms;


import LogicaClasesNew.Fabrica;
import LogicaClasesNew.Estado;
import LogicaClasesNew.IcontroladorCategoria;
import LogicaClasesNew.IcontroladorCliente;
import LogicaClasesNew.IcontroladorLineaOrden;
import LogicaClasesNew.IcontroladorOrdenCompra;
import LogicaClasesNew.IcontroladorProducto;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


public class frmOrdenCompra extends javax.swing.JInternalFrame {

private IcontroladorCategoria ICCATEGORIA;

private IcontroladorCliente ICCLIENTE;

private IcontroladorLineaOrden ICLINEAORD;

private IcontroladorOrdenCompra ICORDENCOMPRA;

private IcontroladorProducto ICPRODUCTO;

    public frmOrdenCompra() {
        
        Fabrica fab = Fabrica.getInstance();
        
        this.ICCATEGORIA = fab.getControladorCategoria();
        this.ICCLIENTE = fab.getControladorCliente();
        this.ICLINEAORD = fab.getControladorLineaOrden();
        this.ICORDENCOMPRA = fab.getControladorOrdenCompra();
        this.ICPRODUCTO = fab.getControladorProducto();
        
        initComponents();
        CrearModeloJT_OrdenCompraClientes();
        CrearModeloJT_OrdenCompraProductos();
        CrearModeloJT_OrdenLineaCompra();
        llenartablaCli();
        iniciarJCB_OrdenCompraCategoria();
        iniciarFechaOrdenCompra();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JB_OrdenCompraCantidad = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        JB_OrdenCompraFinalizar = new javax.swing.JButton();
        JB_OrdenCompraCancelar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        JCB_OrdenCompraCategoria = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        JT_OrdenCompraLineaCompra = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        JT_OrdenCompraProductos = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        JT_OrdenCompraClientes = new javax.swing.JTable();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        JB_OrdenCompraCantidad1 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        JB_OrdenCompraFinalizar1 = new javax.swing.JButton();
        JB_OrdenCompraCancelar1 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        JCB_OrdenCompraCategoria1 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        JT_OrdenCompraLineaCompra1 = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        JT_OrdenCompraProductos1 = new javax.swing.JTable();
        jScrollPane6 = new javax.swing.JScrollPane();
        JT_OrdenCompraClientes1 = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        JTF_InfoUsuarioNickName = new javax.swing.JTextField();
        JL_InfoUsuarioNickName = new javax.swing.JLabel();
        JL_InfoUsuarioNombre = new javax.swing.JLabel();
        JTF_InfoUsuarioNombre = new javax.swing.JTextField();
        JL_UsuarioMail = new javax.swing.JLabel();
        JTF_InfoUsuarioMail = new javax.swing.JTextField();

        setTitle("Orden de Compra");

        JB_OrdenCompraCantidad.setText("Cantidad");
        JB_OrdenCompraCantidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_OrdenCompraCantidadActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Productos IngresadosOrange.png"))); // NOI18N

        JB_OrdenCompraFinalizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FinalizarOrdenCompra.png"))); // NOI18N
        JB_OrdenCompraFinalizar.setToolTipText("Finaliza la Orden de Compra");
        JB_OrdenCompraFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_OrdenCompraFinalizarActionPerformed(evt);
            }
        });

        JB_OrdenCompraCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Cerrar.png"))); // NOI18N
        JB_OrdenCompraCancelar.setToolTipText("Cierra la ventana");
        JB_OrdenCompraCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_OrdenCompraCancelarActionPerformed(evt);
            }
        });

        JCB_OrdenCompraCategoria.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        JCB_OrdenCompraCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione la Categoria" }));
        JCB_OrdenCompraCategoria.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                JCB_OrdenCompraCategoriaItemStateChanged(evt);
            }
        });
        JCB_OrdenCompraCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JCB_OrdenCompraCategoriaActionPerformed(evt);
            }
        });

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/seleccioneCategoriaOrange.png"))); // NOI18N

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/seleccioneProdYCantOrange.png"))); // NOI18N

        JT_OrdenCompraLineaCompra.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        JT_OrdenCompraLineaCompra.setEnabled(false);
        jScrollPane1.setViewportView(JT_OrdenCompraLineaCompra);

        JT_OrdenCompraProductos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        JT_OrdenCompraProductos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JT_OrdenCompraProductosMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(JT_OrdenCompraProductos);

        JT_OrdenCompraClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Email", "NickName"
            }
        ));
        JT_OrdenCompraClientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JT_OrdenCompraClientesMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(JT_OrdenCompraClientes);

        jInternalFrame1.setTitle("Orden de Compra");

        JB_OrdenCompraCantidad1.setText("Cantidad");
        JB_OrdenCompraCantidad1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_OrdenCompraCantidad1ActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Productos IngresadosOrange.png"))); // NOI18N

        JB_OrdenCompraFinalizar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/FinalizarOrdenCompra.png"))); // NOI18N
        JB_OrdenCompraFinalizar1.setToolTipText("Finaliza la Orden de Compra");
        JB_OrdenCompraFinalizar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_OrdenCompraFinalizar1ActionPerformed(evt);
            }
        });

        JB_OrdenCompraCancelar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Cerrar.png"))); // NOI18N
        JB_OrdenCompraCancelar1.setToolTipText("Cierra la ventana");
        JB_OrdenCompraCancelar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_OrdenCompraCancelar1ActionPerformed(evt);
            }
        });

        JCB_OrdenCompraCategoria1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        JCB_OrdenCompraCategoria1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione la Categoria" }));
        JCB_OrdenCompraCategoria1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                JCB_OrdenCompraCategoria1ItemStateChanged(evt);
            }
        });
        JCB_OrdenCompraCategoria1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JCB_OrdenCompraCategoria1ActionPerformed(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/seleccioneCategoriaOrange.png"))); // NOI18N

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/seleccioneProdYCantOrange.png"))); // NOI18N

        JT_OrdenCompraLineaCompra1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        JT_OrdenCompraLineaCompra1.setEnabled(false);
        jScrollPane4.setViewportView(JT_OrdenCompraLineaCompra1);

        JT_OrdenCompraProductos1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        JT_OrdenCompraProductos1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JT_OrdenCompraProductos1MouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(JT_OrdenCompraProductos1);

        JT_OrdenCompraClientes1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Email", "NickName"
            }
        ));
        jScrollPane6.setViewportView(JT_OrdenCompraClientes1);

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrame1Layout.createSequentialGroup()
                                .addGap(113, 113, 113)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 443, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(JB_OrdenCompraFinalizar1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(JB_OrdenCompraCancelar1))
                            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                                .addGap(35, 35, 35)
                                                .addComponent(jLabel5))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrame1Layout.createSequentialGroup()
                                                .addComponent(JCB_OrdenCompraCategoria1, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(27, 27, 27)))
                                        .addGap(46, 46, 46)
                                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                        .addGap(57, 57, 57)
                                        .addComponent(jLabel3)
                                        .addGap(80, 80, 80)
                                        .addComponent(jLabel8)))
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                .addGap(553, 553, 553)
                                .addComponent(JB_OrdenCompraCantidad1))
                            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                .addGap(116, 116, 116)
                                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 922, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(21, 21, 21)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(22, 22, 22)
                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(JB_OrdenCompraCantidad1))
                                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                        .addComponent(JCB_OrdenCompraCategoria1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(123, 123, 123)
                                        .addComponent(jLabel5)))
                                .addGap(78, 78, 78)
                                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(JB_OrdenCompraFinalizar1)
                                    .addComponent(JB_OrdenCompraCancelar1)))
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel11.setText("SELECCIONE CLIENTE");

        JTF_InfoUsuarioNickName.setEditable(false);
        JTF_InfoUsuarioNickName.setForeground(new java.awt.Color(255, 51, 0));
        JTF_InfoUsuarioNickName.setToolTipText("Ingrese un Alias que lo Identificar{a");
        JTF_InfoUsuarioNickName.setCaretColor(new java.awt.Color(255, 51, 0));
        JTF_InfoUsuarioNickName.setDisabledTextColor(new java.awt.Color(255, 51, 0));

        JL_InfoUsuarioNickName.setText("NickName:");

        JL_InfoUsuarioNombre.setText("* Nombre:");

        JTF_InfoUsuarioNombre.setEditable(false);
        JTF_InfoUsuarioNombre.setForeground(new java.awt.Color(153, 0, 153));
        JTF_InfoUsuarioNombre.setToolTipText("Ingrese su Nombre");
        JTF_InfoUsuarioNombre.setDisabledTextColor(new java.awt.Color(153, 0, 153));

        JL_UsuarioMail.setText("*Correo  electronico:");

        JTF_InfoUsuarioMail.setEditable(false);
        JTF_InfoUsuarioMail.setForeground(new java.awt.Color(153, 0, 153));
        JTF_InfoUsuarioMail.setDisabledTextColor(new java.awt.Color(153, 0, 153));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 767, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(42, 42, 42)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addComponent(JL_UsuarioMail)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(JTF_InfoUsuarioMail, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(JL_InfoUsuarioNickName)
                                                .addComponent(JL_InfoUsuarioNombre))
                                            .addGap(38, 38, 38)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(JTF_InfoUsuarioNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(JTF_InfoUsuarioNickName, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(281, 281, 281)
                                .addComponent(JB_OrdenCompraCantidad))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(41, 41, 41)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(JCB_OrdenCompraCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(70, 70, 70)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(jLabel9)
                                            .addGap(145, 145, 145))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(jLabel4)
                                            .addGap(112, 112, 112)))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(JB_OrdenCompraFinalizar)
                                            .addGap(36, 36, 36)
                                            .addComponent(JB_OrdenCompraCancelar)
                                            .addGap(25, 25, 25))
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE))))))))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 422, Short.MAX_VALUE)
                    .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 405, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(JL_InfoUsuarioNickName)
                                    .addComponent(JTF_InfoUsuarioNickName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(JL_InfoUsuarioNombre)
                                    .addComponent(JTF_InfoUsuarioNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JL_UsuarioMail)
                            .addComponent(JTF_InfoUsuarioMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(JCB_OrdenCompraCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(JB_OrdenCompraCantidad)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JB_OrdenCompraFinalizar)
                            .addComponent(JB_OrdenCompraCancelar))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 336, Short.MAX_VALUE)
                    .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 315, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
public int cantidad;
//BOTON CANTIDAD
    private void JB_OrdenCompraCantidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_OrdenCompraCantidadActionPerformed
    //CARGO PRODUCTOS A LA ORDEN
    if (prodseleccionado==null){
            JOptionPane.showMessageDialog(null, "Seleccione un producto");
    
    }
    else {
       cantidad  = 0;
       cantidad = Integer.parseInt(JOptionPane.showInputDialog(null, "Cantidad", "Su producto es: " + prodseleccionado + "\n Ingrese la Cantidad desada",JOptionPane.QUESTION_MESSAGE ));
        OrdenLineaCompra.addRow(new Object[]{prodseleccionado,cantidad});
       //Limpio variables globales
       prodseleccionado=null;
       cantidad=0;
    }//GEN-LAST:event_JB_OrdenCompraCantidadActionPerformed
       
    }
    //FINALIZAR ORDEN DE COMPRA
    private void JB_OrdenCompraFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_OrdenCompraFinalizarActionPerformed

//SE VIENE EL CODIGO>>>>
    //Inicializo variables
    float precio=0;
    float preciototal=0;    
    //Verifico campos
    if (JTF_InfoUsuarioNickName.getText().isEmpty()){
             getToolkit().beep();
            JOptionPane.showMessageDialog(null, "Debe seleccionar un cliente");
            return;
        } 
    if (OrdenLineaCompra.getRowCount()==0){
             getToolkit().beep();
            JOptionPane.showMessageDialog(null, "Debe agregar productos a la compra");
            return;
        }
   
    int numeroOrdenCompra = ICORDENCOMPRA.createOrdenCompra2(fechaactual, precio, JTF_InfoUsuarioNickName.getText(),Estado.RECIBIDA);
    
    JOptionPane.showMessageDialog(null,"Orden generada correctamente, número: " + numeroOrdenCompra );
        
    for (int i = 0; i < OrdenLineaCompra.getRowCount(); i++) {
             
                int lineaproducto=Integer.parseInt(OrdenLineaCompra.getValueAt(i, 0).toString());
                
                int lineacantidad=Integer.parseInt(OrdenLineaCompra.getValueAt(i, 1).toString());

                int Idlinea = ICLINEAORD.IntcreateLineaOrden(lineacantidad, ICPRODUCTO.findProducto(lineaproducto).getPrecio(), ICPRODUCTO.findProducto(lineaproducto).getNumRef());
                
                preciototal = preciototal + ((ICLINEAORD.findLineaOrden(Idlinea).getPrecioactual()) * (ICLINEAORD.findLineaOrden(Idlinea).getCantidad()));
                
                try {
                    ICORDENCOMPRA.addLineaToOrdenCompra(numeroOrdenCompra, Idlinea);
                   
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage());
                }
            }        
    //SETEO PRECIO TOTAL
  //  ICORDENCOMPRA.findOrdenCompra(numeroOrdenCompra).setPrecioTotal(preciototal);
   // NuevaOrden.setPrecioTotal(preciototal);   
    try {
        //LA PERSISTO NUEVAMENTE CON EL NUEVO PRECIO TOTAL DE LA ORDEN
        
       ICORDENCOMPRA.editOrdenCompra2(numeroOrdenCompra,fechaactual,preciototal,JTF_InfoUsuarioNickName.getText(),Estado.RECIBIDA,"","");
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
    }
    
    this.setVisible(false);
       
    }//GEN-LAST:event_JB_OrdenCompraFinalizarActionPerformed

    private void JB_OrdenCompraCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_OrdenCompraCancelarActionPerformed
        //Oculta formulario
        this.setVisible (false);
    }//GEN-LAST:event_JB_OrdenCompraCancelarActionPerformed

    private void JCB_OrdenCompraCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JCB_OrdenCompraCategoriaActionPerformed
  
        
    }//GEN-LAST:event_JCB_OrdenCompraCategoriaActionPerformed
//COMBO CATEGORIA
    private void JCB_OrdenCompraCategoriaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_JCB_OrdenCompraCategoriaItemStateChanged
       // ControladorCategoria jpaCateg = new ControladorCategoria();
        //carga el nombre de la categoria
        //String seleccion = JCB_OrdenCompraCategoria.getSelectedItem().toString(); 
        //Obtengo el listado de productos de la categoria seleccionada
       // Categoria catseleccionada = jpaCateg.findCategoria(seleccion);
        //JOptionPane.showMessageDialog (null,catseleccionada.getNombre());
       // llenartablaProductos(catseleccionada.getListadoProducto());
        llenartablaProductos();
        
    }//GEN-LAST:event_JCB_OrdenCompraCategoriaItemStateChanged
//SELECCION DE PRODUCTO
    public String prodseleccionado;
    private void JT_OrdenCompraProductosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JT_OrdenCompraProductosMouseClicked
        int row= JT_OrdenCompraProductos.getSelectedRow();
        prodseleccionado=(JT_OrdenCompraProductos.getModel().getValueAt(row, 0).toString());
    }//GEN-LAST:event_JT_OrdenCompraProductosMouseClicked

    private void JB_OrdenCompraCantidad1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_OrdenCompraCantidad1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_JB_OrdenCompraCantidad1ActionPerformed

    private void JB_OrdenCompraFinalizar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_OrdenCompraFinalizar1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_JB_OrdenCompraFinalizar1ActionPerformed

    private void JB_OrdenCompraCancelar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JB_OrdenCompraCancelar1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_JB_OrdenCompraCancelar1ActionPerformed

    private void JCB_OrdenCompraCategoria1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_JCB_OrdenCompraCategoria1ItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_JCB_OrdenCompraCategoria1ItemStateChanged

    private void JCB_OrdenCompraCategoria1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JCB_OrdenCompraCategoria1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_JCB_OrdenCompraCategoria1ActionPerformed

    private void JT_OrdenCompraProductos1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JT_OrdenCompraProductos1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_JT_OrdenCompraProductos1MouseClicked

    private void JT_OrdenCompraClientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JT_OrdenCompraClientesMouseClicked
        int row= JT_OrdenCompraClientes.getSelectedRow();
            String nick=(JT_OrdenCompraClientes.getModel().getValueAt(row, 1).toString());
            JTF_InfoUsuarioNickName.setText(ICCLIENTE.findCliente(nick).getNickname());
            JTF_InfoUsuarioNombre.setText(ICCLIENTE.findCliente(nick).getNombre());
            JTF_InfoUsuarioMail.setText(ICCLIENTE.findCliente(nick).getMail());
    }//GEN-LAST:event_JT_OrdenCompraClientesMouseClicked
    
    public static DefaultTableModel modeloproductos;
    
    private void CrearModeloJT_OrdenCompraProductos(){
         try {
             modeloproductos = (new DefaultTableModel(
                null, new String [] {
                "Número de Referencia","Nombre","Precio"}){
                Class[] types = new Class [] {
                java.lang.String.class,
                java.lang.String.class,
                java.lang.String.class
    };
                boolean[] canEdit = new boolean [] {
                false,false,false
                };
                @Override
                public Class getColumnClass(int columnIndex) {
                   return types [columnIndex];
                }
                @Override
                public boolean isCellEditable(int rowIndex, int colIndex){
                   return canEdit [colIndex];
                }
            });
          JT_OrdenCompraProductos.setModel(modeloproductos);
         } catch (Exception e) {
             getToolkit().beep();
             JOptionPane.showMessageDialog(null,e.toString()+"error2");
            }    
     }
     
    public static DefaultTableModel modelo2;
     
     private void CrearModeloJT_OrdenCompraClientes(){
         try {
             modelo2 = (new DefaultTableModel(
                null, new String [] {
                "Email","Nickname"}){
                Class[] types = new Class [] {
                java.lang.String.class,
                java.lang.String.class
    };
                boolean[] canEdit = new boolean [] {
                false,false
                };
                @Override
                public Class getColumnClass(int columnIndex) {
                   return types [columnIndex];
                }
                @Override
                public boolean isCellEditable(int rowIndex, int colIndex){
                   return canEdit [colIndex];
                }
            });
          JT_OrdenCompraClientes.setModel(modelo2);
         } catch (Exception e) {
             JOptionPane.showMessageDialog(null,e.toString());
            }    
     }
     
     public static DefaultTableModel OrdenLineaCompra;
    
     private void CrearModeloJT_OrdenLineaCompra(){
         try {
             OrdenLineaCompra = (new DefaultTableModel(
                null, new String [] {
                "Producto","Cantidad"}){
                Class[] types = new Class [] {
                java.lang.String.class,
                java.lang.String.class
    };
                boolean[] canEdit = new boolean [] {
                false,false
                };
                @Override
                public Class getColumnClass(int columnIndex) {
                   return types [columnIndex];
                }
                @Override
                public boolean isCellEditable(int rowIndex, int colIndex){
                   return canEdit [colIndex];
                }
            });
          JT_OrdenCompraLineaCompra.setModel(OrdenLineaCompra);
         } catch (Exception e) {
             JOptionPane.showMessageDialog(null,e.toString());
            }    
     }
     
     private void llenartablaCli (){
         
        try {
            Object A[] = null;
            for (int i = 0; i < ICCLIENTE.findClienteEntities().size(); i++) {
                modelo2.addRow(A);
                modelo2.setValueAt(ICCLIENTE.findClienteEntities().get(i).getMail(), i, 0);
                modelo2.setValueAt(ICCLIENTE.findClienteEntities().get(i).getNickname(), i, 1);
                
            }
        }
        catch (Exception e){
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
    }
   
    private void Clear_tablaProductos(){
    for (int i = 0; i < JT_OrdenCompraProductos.getRowCount(); i++) {
    modeloproductos.removeRow(i);
    i-=1;
    }
    }
     //Lleno tabla de productos
    private void llenartablaProductos(){
    Clear_tablaProductos();
    String seleccion = JCB_OrdenCompraCategoria.getSelectedItem().toString();
    try {
            Object A[] = null;
            for (int i = 0; i < ICCATEGORIA.findCategoria(seleccion).getListadoProducto().size(); i++) {
                modeloproductos.addRow(A);
                modeloproductos.setValueAt(ICCATEGORIA.findCategoria(seleccion).getListadoProducto().get(i).getNumRef(), i, 0);
                modeloproductos.setValueAt(ICCATEGORIA.findCategoria(seleccion).getListadoProducto().get(i).getNombre(), i, 1);
                modeloproductos.setValueAt(ICCATEGORIA.findCategoria(seleccion).getListadoProducto().get(i).getPrecio(), i, 2);
                }
        }
    catch (Exception e)
        {
        JOptionPane.showMessageDialog(this, e.getMessage());
        }
    }
        
    private void iniciarJCB_OrdenCompraCategoria() {
        try {
           for(int i = 0; i < ICCATEGORIA.findCategoriaEntities().size(); i++) {
                
                boolean tiene = ICCATEGORIA.findCategoriaEntities().get(i).getTieneProductos();
                //Si tiene productos me interesa mostrarlo
                if (tiene){
                String nickname = ICCATEGORIA.findCategoriaEntities().get(i).getNombre();
                JCB_OrdenCompraCategoria.addItem(nickname);
                
                }
                
                }
        }
        catch (Exception e){
            getToolkit().beep();
            JOptionPane.showMessageDialog(this, e.getMessage());
        }       
    }
    
    public String fechaactual;
    private void iniciarFechaOrdenCompra() {
         
        Calendar fecha = new GregorianCalendar();
        //Obtenemos el valor del año, mes, día...usando el método get y el parámetro correspondiente
        int anio = fecha.get(Calendar.YEAR);
        int mes = fecha.get(Calendar.MONTH);
        int dia = fecha.get(Calendar.DAY_OF_MONTH);
        fechaactual= + dia + "/" + (mes+1) + "/" + anio;
   }
        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JB_OrdenCompraCancelar;
    private javax.swing.JButton JB_OrdenCompraCancelar1;
    private javax.swing.JButton JB_OrdenCompraCantidad;
    private javax.swing.JButton JB_OrdenCompraCantidad1;
    private javax.swing.JButton JB_OrdenCompraFinalizar;
    private javax.swing.JButton JB_OrdenCompraFinalizar1;
    private javax.swing.JComboBox JCB_OrdenCompraCategoria;
    private javax.swing.JComboBox JCB_OrdenCompraCategoria1;
    private javax.swing.JLabel JL_InfoUsuarioNickName;
    private javax.swing.JLabel JL_InfoUsuarioNombre;
    private javax.swing.JLabel JL_UsuarioMail;
    private javax.swing.JTextField JTF_InfoUsuarioMail;
    private javax.swing.JTextField JTF_InfoUsuarioNickName;
    private javax.swing.JTextField JTF_InfoUsuarioNombre;
    private javax.swing.JTable JT_OrdenCompraClientes;
    private javax.swing.JTable JT_OrdenCompraClientes1;
    private javax.swing.JTable JT_OrdenCompraLineaCompra;
    private javax.swing.JTable JT_OrdenCompraLineaCompra1;
    private javax.swing.JTable JT_OrdenCompraProductos;
    private javax.swing.JTable JT_OrdenCompraProductos1;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration//GEN-END:variables

    
    
     }
